<!--#include file="../inc/easp/easp.asp"-->
<!--#include file="../inc/conn1.asp"-->
<!--#include file="../inc/checklogin.asp"-->
<!--#include file="../inc/easyide.asp"-->
<% CheckLogin("../index.asp") %>
<%
  If Session("Authority") = "1" Then
    Response.Write "<script type=""text/javascript"">alert('Delete failed!');top.location.href='index.asp';</script>"
  End if
%>
<%
  dim rs
  dim y_id,g_id,operate
  y_id = Easp.Get("y_id") '获取要操作的国家ID
  g_id = Easp.Get("g_id") '获取所属分组ID
  operate = Easp.Get("op")'获取操作类型。即是添加还是修改
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Times Control</title>
<link rel="stylesheet" type="text/css" href="../css/theme.css" />
<link rel="stylesheet" type="text/css" href="../css/style.css" />
<script type="text/javascript">
  var StyleFile = "theme" + document.cookie.charAt(6) + ".css";
  document.writeln('<link rel="stylesheet" type="text/css" href="../css/' + StyleFile + '">');
  
  function IsDirectory(str)
  {
	  var regexp = /^\/[a-zA-Z0-9_\.]+/;
	  if (!regexp.exec(str)) return false;
	  return true;
  }

  function checkform(obj)
  {
  	if (obj["txtGroupDir"].value == "")
	  {
		  alert("Please Input Group Dir!");		
		  obj["txtGroupDir"].focus();
		  return false;
	  }
	
	  for(i = 1; i <= 7; ++i)
	  {
	  	if (obj["ot_HH" + i].value == "")
		{
		    alert("Please Input Office time hour " + i + " !");
		    obj["ot_HH" + i].focus();
		    return false;
	    }
	    if (obj["ot_MM" + i].value == "")
		{
		    alert("Please Input Office time minute " + i + " !");
		    obj["ot_MM" + i].focus();
		    return false;
	    } 
	    if (obj["ct_HH" + i].value == "")
		{
		    alert("Please Input Closing time hour " + i + " !");
		    obj["ct_HH" + i].focus();
		    return false;
	    } 
	    if (obj["ct_MM" + i].value == "")
		{
		    alert("Please Input Closing time minute " + i + " !");
		    obj["ct_MM" + i].focus();
		    return false;
	    } 
	  }
	  
	  if(!IsDirectory(obj["txtGroupDir"].value))
	  {
		  alert("Group Dir Format Wrong!You must start with \"/\"");
		  obj["txtGroupDir"].focus();
		  return false;
	  }	
	  
	  for(i = 1; i <= 7; ++i)
	  {
		  othh = parseInt(obj["ot_HH" + i].value);
		  if (othh > 23)
		  {
			  alert("Hour Format wrong!");
			  obj["ot_HH" + i].focus();
			  return false;
		  }
		  
		  otmm = parseInt(obj["ot_MM" + i].value);
		  if (otmm > 59)
		  {
			  alert("Minute Format wrong!");
			  obj["ot_MM" + i].focus();
			  return false;
		  }
		  
		  cthh = parseInt(obj["ct_HH" + i].value);
		  if (cthh > 23)
		  {
			  alert("Hour Format wrong!");
			  obj["ct_HH" + i].focus();
			  return false;
		  }
		  
		  ctmm = parseInt(obj["ct_MM" + i].value);
		  if (ctmm > 59)
		  {
			  alert("Minute Format wrong!");
			  obj["ct_MM" + i].focus();
			  return false;
		  }
	  }
	  
	  return true;
  }
</script>
<!--[if IE]>
<link rel="stylesheet" type="text/css" href="css/ie-sucks.css" />
<![endif]-->
</head>
<body>
<div id="container">
	<div id="header">
    <div id="divAccount" style="float:right;">
        <a href="../user/account.asp" style="color:white">Account</a>&nbsp;&nbsp;&nbsp;&nbsp;
        <a href="../inc/logout.asp" style="color:white">Logout</a>
      </div>
		<h2>Times Control</h2>
		<div id="topmenu">
			<ul>
				<li><a href="../main.asp">Home</a></li>
				<%
				   If Session("Authority")="0" Then 
				     Easp.wc "<li><a href='../Country/index.asp'>Country</a></li>"
				   End if
				%>
				<li><a href="../Holiday/index.asp">Holiday</a></li>
				<li class="current"><a href="#">Times</a></li>
				<li><a href="../wallboard/index.asp">WallBoard</a></li>
				<%
				   If Session("Authority")="0" Then 
				       Response.Write("<li><a href='../user/index.asp'>User</a></li>")
				   End if
				%>
				<li><% If Session("Passed")=true Then %><a href="../inc/logout.asp">Logout</a><% End If %></li>
			</ul>
		</div>
	</div>
	<div id="top-panel">
		<div id="panel">
			<ul>
				<li><a href="<%=request.serverVariables("Http_REFERER")%>" class="goback">GoBack</a></li>
			</ul>
		</div>
	</div>
	<div id="wrapper">
		<div id="content">
			<form id="form" name="form" action="times.asp" method="post" onSubmit="return checkform(this)">
				<div id="box">
					<%
					  dim rs1,rs2
					  dim countryName,groupName
					  Set rs1 = Easp.db.GetRecordBySql("select * from Country where y_id=" & y_id & "")					  
					  If not Easp.IsN(rs1) Then
					  	countryName = trim(rs1("CountryName"))
					  End If
					  Easp.db.C(rs1)
					 
					  Set rs2 = Easp.db.GetRecordBySql("select * from [Group] where ID=" & g_id & "")
					  if not Easp.IsN(rs2) Then
					  	groupName = trim(rs2("GroupName"))
					  End if					  
					  Easp.db.c(rs2)
					
					  select case operate
					  	case "add"
					  	  Easp.wc "<h3>Add New Times - " & countryName & " - " & groupName & "</h3>"
					  	case "modify"
					  	  Easp.wc "<h3>Modify Times - " & countryName & " - " & groupName & "</h3>"
					  end select
					%>					
					<table width="100%" style="text-align: center;">
						<thead>
							<tr>
								<th width="81" class="a-center"><a href="#">Week</a></th>
								<th width="360"><a href="#">Open</a></th>
								<th width="360"><a href="#">Close</a></th>
							</tr>
						</thead>
						<tbody>
						<%
						'获取对应组的存放目录
						  dim rsgroup,savepath
						  savepath = ""
						  set rsgroup = Easp.db.GetRecordBySql("select * from [Group] where ID=" & g_id)
						  if not Easp.IsN(rsgroup) Then
						  	savepath = Trim(rsgroup("TimePath"))	
						  	if right(savepath, 1) <> "/" and right(savepath, 1) <> "\" then
  	              savepath = savepath & "/"
                end if					  	
						  end if
						  Easp.db.C(rsgroup)
						
						  dim i
						  select case operate
						  	case "add"
						  	  '添加新记录
						  	  for i = 1 to 7
							      Easp.wc "<tr>"
							      Easp.wc "<td class=""a-center"">" & i & "</td>"
							      Easp.wc "<td><span>hh</span><input name=""ot_HH" & i & """ id=""ot_HH" & i & """ type=""text"" tabindex=""1"" class=""ipt"" /><span>mm</span><input name=""ot_MM" & i & """ id=""ot_MM" & i & """ type=""text"" tabindex=""1"" class=""ipt"" /></td>"
							      Easp.wc "<td><span>hh</span><input name=""ct_HH" & i & """ id=""ct_HH" & i & """ type=""text"" tabindex=""1"" class=""ipt"" /><span>mm</span><input name=""ct_MM" & i & """ id=""ct_MM" & i & """ type=""text"" tabindex=""1"" class=""ipt"" /></td>"
							      Easp.wc "</tr>"
							    next
						  	case "modify"
						  	  '修改已有记录
						  	  Set rs = Easp.db.GetRecordDetail("Country", Array("y_id:" & y_id, "g_id:" & g_id))	
						  	  If Not Easp.IsN(rs) Then
						  	  	dim timesFile,Flag
						  	  	timesFile = Trim(rs("TimesFile"))
						  	  	If timesFile <> "" Then
						  	  		timesFile = savepath & timesFile
						  	  		If file_exists(timesFile) Then
						  	  			Flag = true
						  	  			
						  	  			dim doc
						  	  			Set doc = xml_load(timesFile)						  	  			
						  	  			for i = 1 to 7
							            Easp.wc "<tr>"
							            Easp.wc "<td class=""a-center"">" & i & "</td>"
							            Easp.wc "<td><span>hh</span><input name=""ot_HH" & i & """ id=""ot_HH" & i & """ type=""text"" tabindex=""1"" class=""ipt"" value='" & doc.ChildNodes.item(i - 1).Text & "' /><span>mm</span><input name=""ot_MM" & i & """ id=""ot_MM" & i & """ type=""text"" tabindex=""1"" class=""ipt"" value='" & doc.ChildNodes.item(i + 6).Text & "' /></td>"
							            Easp.wc "<td><span>hh</span><input name=""ct_HH" & i & """ id=""ct_HH" & i & """ type=""text"" tabindex=""1"" class=""ipt"" value='" & doc.ChildNodes.item(i + 13).Text & "' /><span>mm</span><input name=""ct_MM" & i & """ id=""ct_MM" & i & """ type=""text"" tabindex=""1"" class=""ipt"" value='" & doc.ChildNodes.item(i + 20).Text & "' /></td>"
							            Easp.wc "</tr>"
							          next
							          Set doc = nothing
						  	  		Else
						  	  			Flag = false
						  	  		End If
						  	    Else'文件不存在
						  	    	Flag = false
						  	    End If
						  	    Easp.db.C(rs)
						  	    
						  	    If Flag = false Then
						  	    	operate = "add"
						  	    	for i = 1 to 7
							          Easp.wc "<tr>"
							          Easp.wc "<td class=""a-center"">"&i&"</td>"
							          Easp.wc "<td><span>hh</span><input name=""ot_HH"&i&""" id=""ot_HH"&i&""" type=""text"" tabindex=""1"" class=""ipt"" /><span>mm</span><input name=""ot_MM"&i&""" id=""ot_MM"&i&""" type=""text"" tabindex=""1"" class=""ipt"" /></td>"
							          Easp.wc "<td><span>hh</span><input name=""ct_HH"&i&""" id=""ct_HH"&i&""" type=""text"" tabindex=""1"" class=""ipt"" /><span>mm</span><input name=""ct_MM"&i&""" id=""ct_MM"&i&""" type=""text"" tabindex=""1"" class=""ipt"" /></td>"
							          Easp.wc "</tr>"
							        next
						  	    End If
						  	  End If						    	
						  end select
						%>
						</tbody>
					</table>
					<div id="pager">
						<%
						  Easp.wc "<input type='hidden' id='txtGroupDir' name='txtGroupDir' value='" & savepath & "' />"
						  Easp.wc "<input type='hidden' id='Country' name='Country' value='" & y_id & "' />"
						  Easp.wc "<input type='hidden' id='Group' name='Group' value='" & g_id & "' />"
						  Easp.wc "<input type='hidden' id='Operate' name='Operate' value='" & operate & "' />"
						  select case operate
						  	case "add"					  	  
						      Easp.wc "<input class='btn' type='submit' value='Save' />"						      
						  	case "modify"
						      Easp.wc "<input class='btn' type='submit' value='Alter' />"
						     
						  end select
						  Easp.wc "<input name='reset' type='reset' class='btn' value='Reset' />"
						%>
					</div>
				</div>
			</form>
		</div>
	</div>
	<!--#include file="../inc/footer.asp" -->
</div>
</body>
</html>
